package com.designMode.chainOfResponsibility;

/**
 * @author 顾博君
 * @ClassName Client
 * @Date 2016-1-6 下午2:55:56
 * @Function 场景类
 */
public class Client {
    public static void main(String[] args) {
        Level l1 = new Level(1);
        Level l2 = new Level(2);
        Level l3 = new Level(3);
        Handler handler1 = new ConcreteHandler(l1, new Response(1));// 处理者1
        Handler handler2 = new ConcreteHandler(l2, new Response(2));// 处理者2
        Handler handler3 = new ConcreteHandler(l3, new Response(3));// 处理者3
        // 形成责任链
        handler1.setNext(handler2);
        handler2.setNext(handler3);
        // 执行责任链，获取响应,可以从不同的处理者开始找请求的处理等级
//        Response response = handler1.handleMessage(new Request(l1));
//        Response response = handler1.handleMessage(new Request(l2));
//        Response response = handler2.handleMessage(new Request(l3));
        Response response = handler1.handleMessage(new Request(l3));
        if (response != null) {
            response.show();
        } else {
            System.out.println("没有处理者处理请求");
        }
    }
}
